/**
 * 部门管理初始化
 */
var SevenReport = {
    id: "SevenReportTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
SevenReport.initColumn = function () {
    var columns = [
        {
            field: '',
            title: '',
            visible: false,
            formatter: function (value, row, index) {
                return index + 1;
            }
        },
        {
            title: '一级分类', field: 'rirstClassification', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                if ((index + 1) % 5 == 1) {
                    return value;
                } else {
                    return "";
                }
            }
        },
        {
            title: '新老客', field: 'newOldGuests', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                if ((index + 1) % 5 == 1) {
                    return "新客首次";
                } else if ((index + 1) % 5 == 2) {
                    return "新客二次";
                } else if ((index + 1) % 5 == 3) {
                    return "新客";
                } else if ((index + 1) % 5 == 4) {
                    return "老客";
                } else if ((index + 1) % 5 == 0) {
                    return "合计";
                }
            }
        },
        {title: '门诊量', field: 'outpatientVolume', align: 'center', valign: 'middle', width: '50px'},
        {title: '成交量', field: 'volume', align: 'center', valign: 'middle', width: '50px'},
        {
            title: '成交率', field: 'turnoverRate', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                if (row.outpatientVolume == 0) {
                    return "0.00";
                } else {
                    return ((row.volume) / (row.outpatientVolume)).toFixed(2);
                }
            }
        },
        {
            title: '科室业绩', field: 'departmentPerformance', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                if (value == null || value == "") {
                    return "0.00";
                } else {
                    return value;
                }
            }
        },
        {
            title: '人均消费额', field: 'perCapitaConsumption', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                if (row.volume == 0) {
                    return "0.00";
                } else {
                    return ((row.departmentPerformance) / (row.volume)).toFixed(2);
                }
            }
        },
        {
            title: '门诊量占比', field: 'outpatientVolumeRatio', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {

            }
        },
        {title: '成交量占比', field: 'volumeRatio', align: 'center', valign: 'middle', width: '50px'},
        {title: '成交额占比', field: 'turnoverRatio', align: 'center', valign: 'middle', width: '50px'},
    ]
    return columns;
};

/**
 * 检查是否选中
 */
SevenReport.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        SevenReport.seItem = selected[0];
        return true;
    }
};

/**
 * 查询预约客户列表
 */
SevenReport.search = function () {
    SevenReport.table.refresh({query: SevenReport.formParams()});
};

/**
 * 关闭此对话框
 */
SevenReport.close = function () {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}


SevenReport.formParams = function () {
    var queryData = {};
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    queryData['value'] = $("#value").val();
    queryData['dimensionSelection'] = $("#dimensionSelection").val();
    queryData['dimensionSelections'] = $("#dimensionSelections").val();
    console.log(queryData);
    return queryData;
}

SevenReport.formParamss = function () {
    var queryData = {};
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    queryData['value'] = $("#value").val();
    queryData['dimensionSelection'] = $("#dimensionSelection").val();
    queryData['dimensionSelections'] = $("#dimensionSelections").val();
    console.log(queryData);
    return queryData;
}

$(function () {
    var defaultColunms = SevenReport.initColumn();
    var table = new BSTable(SevenReport.id, "/sevenReport/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(SevenReport.formParams());
    SevenReport.table = table.init();
    SevenReport.table.refresh({query: SevenReport.formParams()});
    var i=0
    setInterval(
        function () {//定时执行方法内容
            if(i<1){
                SevenReport.table.refresh({query: SevenReport.formParams()});
            }
            i++
        }, 500);
});
